class Trie {
private:
    char val;
    vector<Trie*> children;
public:
    /** Initialize your data structure here. */
    Trie(char c) {
        val = c;
        children = {};
    }
    Trie() {
        val = ' ';
        children = {};
    }
    
    /** Inserts a word into the trie. */
    void insert(string word) {
        Trie* temp = this;
        for(auto n : word + " ")
        {
            bool exist = false;
            for(auto m : temp -> children)
            {
                if(m -> val == n) 
                {
                    temp = m;
                    exist = true;
                    break;
                }
            }
            if(!exist)
            {
                Trie* node = new Trie(n);
                temp -> children.push_back(node);
                temp = node;
            }
        }
    }
    
    /** Returns if the word is in the trie. */
    bool search(string word) {
        Trie* temp = this;
        for(auto n : word + " ")
        {
            bool exist = false;
            for(auto m : temp -> children)
            {
                if(m -> val == n)
                {
                    temp = m;
                    exist = true;
                    break;
                }
            }
            if(!exist) return false;
        }
        return true;
    }
    
    /** Returns if there is any word in the trie that starts with the given prefix. */
    bool startsWith(string prefix) {
        Trie* temp = this;
        for(auto n : prefix)
        {
            bool exist = false;
            for(auto m : temp -> children)
            {
                if(m -> val == n)
                {
                    temp = m;
                    exist = true;
                    break;
                }
            }
            if(!exist) return false;
        }
        return true;
    }
};

/**
 * Your Trie object will be instantiated and called as such:
 * Trie obj = new Trie();
 * obj.insert(word);
 * bool param_2 = obj.search(word);
 * bool param_3 = obj.startsWith(prefix);
 */
